package org.codert.codertadmin.web.controller;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: TanJingyu
 * @create: 2021-08-13 14:20
 **/
@RestController
@RequestMapping("/jackson")
public class JacksonController {

    public JacksonController(ObjectProvider<List<JacksonSon>> jacksonSons) {
        List<JacksonSon> ifAvailable = jacksonSons.getIfAvailable();
    }

    @GetMapping
    public Object jackson() {
        JacksonSon jacksonSon = new JacksonSon();
        jacksonSon.setName("王吉");
        jacksonSon.setAge(20);

        return jacksonSon;
    }

    @Getter
    @Setter
    public static class JacksonFather {
        @JsonProperty("username")
        private String name;
    }

    @Getter
    @Setter
    public static class JacksonSon extends JacksonFather{
        @JsonProperty("nianling")
        private Integer age;
    }
}
